﻿using System;

namespace octalforty.Syndication.Core.Rss
{
    /// <summary>
    /// Represents a single item of the <see cref="RssChannel"/>.
    /// </summary>
    /// <remarks>
    /// An item may represent a "story" -- much like a story in a newspaper or magazine; if so its description 
    /// is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, 
    /// if so, the description contains the text (entity-encoded HTML is allowed), and the link and title may be omitted.
    /// </remarks>
    public class RssItem : RssEntityBase, ISyndicationFeedItem
    {
        #region Private Member Variables
        private IPerson author;
        private String commentsPageUrl = String.Empty;
        private RssItemEnclosure enclosure;
        private RssItemGuid guid;
        private RssItemSource source;
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets or sets a <see cref="String"/> which contains the URL of a page for 
        /// comments relating to the item.
        /// </summary>
        public String CommentsPageUrl
        {
            get { return commentsPageUrl; }
            set { commentsPageUrl = value; }
        }

        /// <summary>
        /// Gets or sets a reference to the <see cref="RssItemEnclosure"/> which
        /// describes a media object that is attached to the item.
        /// </summary>
        public RssItemEnclosure Enclosure
        {
            get { return enclosure; }
            set { enclosure = value; }
        }

        /// <summary>
        /// Gets or sets a reference to the <see cref="RssItemGuid"/> which
        /// contains the unique identifier of the item.
        /// </summary>
        public RssItemGuid Guid
        {
            get { return guid; }
            set { guid = value; }
        }

        /// <summary>
        /// Gets or sets a reference to the <see cref="RssItemSource"/> which
        /// describes the RSS channel this item came from.
        /// </summary>
        public RssItemSource Source
        {
            get { return source; }
            set { source = value; }
        }
        #endregion

        /// <summary>
        /// Initializes a new instance of <see cref="RssItem"/> class.
        /// </summary>
        public RssItem()
        {
        }

        /// <summary>
        /// Initializes a new instance of <see cref="RssItem"/> class
        /// with a given title, link and description.
        /// </summary>
        /// <param name="title"></param>
        /// <param name="link"></param>
        /// <param name="description"></param>
        public RssItem(String title, String link, String description) : 
            base(title, link, description)
        {
        }

        #region ISyndicationFeedItem Members
        /// <summary>
        /// Gets or sets a <see cref="String"/> which contains copyright notice 
        /// for content in the <see cref="ISyndicationFeedItem"/>.
        /// </summary>
        /// <example>Copyright 2002, Spartanburg Herald-Journal</example>
        public String Copyright
        {
            get { return String.Empty; }
            set { }
        }

        /// <summary>
        /// Gets or sets the <see cref="IPerson"/> which represents a person
        /// who is the author of the <see cref="ISyndicationFeedItem"/>.
        /// </summary>
        public IPerson Author
        {
            get { return author; }
            set { author = value; }
        }

        /// <summary>
        /// Gets or sets the <see cref="DateTime"/> which indicates the date and time
        /// indicating the most recent instant in time when the <see cref="ISyndicationFeedItem"/> was modified 
        /// in a way the publisher considers significant.
        /// </summary>
        public DateTime? UpdatedOn
        {
            get { return null; }
            set { }
        }

        /// <summary>
        /// Gets or sets a <see cref="String"/> which contains a permanent, universally unique
        /// identifier for the <see cref="ISyndicationFeedItem"/>.
        /// </summary>
        public String UniqueIdentifier
        {
            get { return Guid == null ? null : Guid.Guid; }
            set
            {
                guid = new RssItemGuid(value, true);
            }
        }
        #endregion
    }
}
